﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace GenUI.WPF.GenControls.Converter
{
    [ValueConversion(typeof(DateTime), typeof(string))]
    internal class TimeToStrConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         => value is DateTime Dt ? Dt.ToString("yyyy-MM-dd HH:mm:ss") : null;
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         => DateTime.TryParse(value.ToString(), out DateTime Dt) ? Dt : DateTime.Now;
    }
}
